package web.java.login;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class indexServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setCharacterEncoding("gbk");
		
		//得到session
		HttpSession session=req.getSession(false);
		String name=null;
		if(session!=null){
			//表示有session存在
			name=(String)session.getAttribute("name");
		}else{
			//返回登录界面
			resp.sendRedirect(req.getContextPath()+"/login.html");
			return;
		}
		if(name==null){
			resp.sendRedirect(req.getContextPath()+"/login.html");
		}
		//得到转发来的时间
		//String time=(String)req.getAttribute("time");
		
		String html="<html><head><title>主界面</title><head><body><p>欢迎"+name+"登录系统！</p><p><a href='"+req.getContextPath()+"/loginout'>退出系统</a></p></body></html>";
		resp.getWriter().write(html);
	}
}
